package com.huawen.cms.app.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huawen.cms.app.entity.UserInfo;
import com.huawen.cms.app.service.UserInfoService;
import com.huawen.cms.app.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("/userInfo")
@RestController
public class UserInfoController extends  BaseController {

    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    public UserInfo getById(Long id) {
        UserInfo userInfo = (UserInfo) userInfoService.getById(id);
        return userInfo;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public UserInfo insert(@RequestBody UserInfo userInfo) {
        userInfoService.insert(userInfo);
        return userInfo;
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public UserInfo update(@RequestBody UserInfo userInfo) {
        userInfoService.update(userInfo);
        return userInfo;
    }

    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    public List<UserInfo> getList(@RequestBody UserInfo userInfo) {
        List<UserInfo> list=userInfoService.getList(userInfo);
        return list;
    }


    @RequestMapping(value = "/getPagerList", method = RequestMethod.POST)
    public PageInfo<UserInfo> getPagerList(@RequestBody UserInfo userInfo) {
        Pager pager=getCurrentPager();
        PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<UserInfo> list=userInfoService.getList(userInfo);
        PageInfo<UserInfo> pageInfo = new PageInfo<UserInfo>(list);
        return pageInfo;
    }

}
